﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MoneyManagerNET.Presentation.ViewModel
{
    using Model;
    using System.Windows.Input;
    using MoneyManagerNET.Presentation.ViewModel.Base;
    public class RelocateCategoryViewModel : ViewModelBase
    {
        public RelocateCategoryViewModel()
        {
            SelectFromCategoryCommand = new Infrastructure.DelegateCommand((o) => PromptFromCategory());
            SelectToCategoryCommand = new Infrastructure.DelegateCommand((o) => PromptToCategory());
        }

        ICategory _toCategory;

        public ICategory ToCategory
        {
            get { return _toCategory; }
            set { _toCategory = value; this.OnChange(() => ToText); }
        }

        ISubCategory _toSubCategory;

        public ISubCategory ToSubCategory
        {
            get { return _toSubCategory; }
            set { _toSubCategory = value; this.OnChange(() => ToText); }
        }


        ICategory _fromCategory;

        public ICategory FromCategory
        {
            get { return _fromCategory; }
            set { _fromCategory = value; this.OnChange(() => FromText); }
        }


        ISubCategory _fromSubCategory;

        public ISubCategory FromSubCategory
        {
            get { return _fromSubCategory; }
            set { _fromSubCategory = value; this.OnChange(() => FromText); }
        }


        public string FromText { get { return FromCategory == null ? "select source category" : (FromSubCategory == null) ? FromCategory.Name : FromCategory.Name + " : " + FromSubCategory.Name; } }

        public string ToText { get { return ToCategory == null ? "select destination category" : (ToSubCategory == null) ? ToCategory.Name : ToCategory.Name + " : " + ToSubCategory.Name; } }


        public ICommand SelectFromCategoryCommand { get; protected set;}
        public void PromptToCategory()
        {
            var cvm = new Presentation.ViewModel.CategoryListViewModel();
            var r = cvm.ShowDialog();
            if (r.HasValue && r.Value)
            {
                ToCategory = cvm.Category;
                ToSubCategory = cvm.SubCategory;
            }
        }


        public ICommand SelectToCategoryCommand { get; protected set; }
        public void PromptFromCategory()
        {
            var cvm = new Presentation.ViewModel.CategoryListViewModel();
            var r = cvm.ShowDialog();
            if (r.HasValue && r.Value)
            {
                FromCategory = cvm.Category;
                FromSubCategory = cvm.SubCategory;
            }
        }

    }
}
